package com.horizon.service.impl;

import com.horizon.mapper.IdWorkConfMapper;
import com.horizon.pojo.IdWorkConf;
import com.horizon.pojo.IdWorkerBuilder;
import com.horizon.service.ConfigureDbService;
import com.horizon.util.IdWorker;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ConfigureDbServiceImpl implements ConfigureDbService {

    @Resource
    private IdWorkConfMapper idWorkConfMapper;

    @Override
    public long initCenterIdWorkId(IdWorkConf idWorkConf) {
        idWorkConfMapper.insertCenterIdWorkId(idWorkConf);
        return idWorkConf.getWorkerId();
    }

    /**
     * 获得id生成对象
     */
    public IdWorker getIdWorker() {
        return IdWorkerBuilder.ID_WORKER.getIdWorker();
    }
}
